package c.x.jy.service.service.impl;

import c.x.jy.dao.dto.BusinessWalletEntityDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.Query;

import c.x.jy.dao.dao.BusinessWalletDao;
import c.x.jy.dao.entity.BusinessWalletEntity;
import c.x.jy.service.service.BusinessService;
import c.x.jy.service.service.BusinessWalletService;
import org.apache.commons.lang3.StringUtils;


@Service("businessWalletService")
public class BusinessWalletServiceImpl extends ServiceImpl<BusinessWalletDao, BusinessWalletEntity> implements BusinessWalletService {
	
	@Autowired
	private BusinessService businessService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        	QueryWrapper<BusinessWalletEntity> query= 	 new QueryWrapper<BusinessWalletEntity>() ;
    	if(params.get("searchKey")!=null&&params.get("searchValue")!=null&&!StringUtils.isEmpty(params.get("searchKey").toString())&&!StringUtils.isEmpty(params.get("searchValue").toString()))
    	    query.eq(  params.get("searchKey").toString(), params.get("searchValue"));
        if(params.get("businessId")!=null) 	query.eq("business_id", params.get("businessId"));
        IPage<BusinessWalletEntity> page = this.page(
                new Query<BusinessWalletEntity>().getPage(params),
                 query
        );

        return new PageUtils(page);
    }

	@Override
	public BusinessWalletEntity selectbusinessWallentByBusinessIdForUpdate(Long businessId) { 
		
		return this.getBaseMapper().selectbusinessWallentByBusinessIdForUpdate(selectbusinessWallentByBusinessId(businessId).getId());
	}
	
	public BusinessWalletEntity selectbusinessWallentByBusinessId(Long businessId) {
		QueryWrapper<BusinessWalletEntity> query =new QueryWrapper<BusinessWalletEntity>();
		query.lambda().eq(BusinessWalletEntity::getBusinessId, businessId);
		return this.getBaseMapper().selectOne(query );
		
	}

	@Override
	public BusinessWalletEntityDto getDtoById(Long businessId) {

		return this.getBaseMapper().getDtoById(businessId);
	}
}
